package com.ruoyi.sample.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.experiment.domain.Project;
import com.ruoyi.experiment.domain.SampleRecovery;
import com.ruoyi.sample.model.RItem;
import com.ruoyi.sample.model.SItem;
import com.ruoyi.sample.service.ISampleRecoveryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 样品回收Controller
 *
 * @author ruoyi
 * @date 2024-06-11
 */
//@RestController
//@RequestMapping("/recovery")
public class SampleRecoveryController extends BaseController
{
//    @Autowired
    private ISampleRecoveryService sampleRecoveryService;

    /**
     * 查询样品回收列表
     */
    //@preAuthorize("@ss.hasPermi('system:recovery:list')")
    @GetMapping("/list")
    public TableDataInfo list(SampleRecovery sampleRecovery)
    {
        startPage();
        List<SampleRecovery> list = sampleRecoveryService.selectSampleRecoveryList(sampleRecovery);
        return getDataTable(list);
    }

    /**
     * 导出样品回收列表
     */
    //@preAuthorize("@ss.hasPermi('system:recovery:export')")
    @Log(title = "样品回收", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SampleRecovery sampleRecovery)
    {
        List<SampleRecovery> list = sampleRecoveryService.selectSampleRecoveryList(sampleRecovery);
        ExcelUtil<SampleRecovery> util = new ExcelUtil<SampleRecovery>(SampleRecovery.class);
        util.exportExcel(response, list, "样品回收数据");
    }

    /**
     * 获取样品回收详细信息
     */
    //@preAuthorize("@ss.hasPermi('system:recovery:query')")
    @GetMapping(value = "/{recoveryId}")
    public AjaxResult getInfo(@PathVariable("recoveryId") Long recoveryId)
    {
        return success(sampleRecoveryService.selectSampleRecoveryByRecoveryId(recoveryId));
    }

    /**
     * 新增样品回收
     */
    //@preAuthorize("@ss.hasPermi('system:recovery:add')")
    @Log(title = "样品回收", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SampleRecovery sampleRecovery)
    {
        return toAjax(sampleRecoveryService.insertSampleRecovery(sampleRecovery));
    }

    /**
     * 修改样品回收
     */
    //@preAuthorize("@ss.hasPermi('system:recovery:edit')")
    @Log(title = "样品回收", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SampleRecovery sampleRecovery)
    {
        return toAjax(sampleRecoveryService.updateSampleRecovery(sampleRecovery));
    }

    /**
     * 删除样品回收
     */
    //@preAuthorize("@ss.hasPermi('system:recovery:remove')")
    @Log(title = "样品回收", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recoveryIds}")
    public AjaxResult remove(@PathVariable Long[] recoveryIds)
    {
        return toAjax(sampleRecoveryService.deleteSampleRecoveryByRecoveryIds(recoveryIds));
    }

    @GetMapping("item")
    public TableDataInfo listItem(Project project){
        startPage();
        List<RItem> sItems = sampleRecoveryService.selectAllItem(project);
        return getDataTable(sItems);
    }
}

